﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Com.Rivyer.Web.ip
{
    public partial class iptodelete : System.Web.UI.Page
    {
        private readonly BLL.ipaddressBll ipbll = new BLL.ipaddressBll();
        private readonly BLL.useroperatelogBll logbll = new BLL.useroperatelogBll();

        protected void Page_Load(object sender, EventArgs e)
        {
            string iptodelete = Request.Params["delete"];
            System.Data.DataSet iptodeleteds = ipbll.GetList(string.Format("id in ({0})", iptodelete));
            iptodeletegrid.DataSource = iptodeleteds;
            iptodeletegrid.DataBind();
        }

        protected void btn_delete_Click(object sender, EventArgs e)
        {
            Model.ipaddressModel ipmodel = new Model.ipaddressModel();
            string iptodelete = Request.Params["delete"];
            string[] ipdeletes = iptodelete.Split(',');
            logbll.AddLog(Session["username"].ToString(), "收回", string.Format("{0}条IP地址", ipdeletes.Length));

            for (int i = 0; i < ipdeletes.Length; i++)
            {
                ipmodel.id = int.Parse(ipdeletes[i].ToString());
                ipmodel.ip = ipbll.GetModel(ipmodel.id).ip;
                ipmodel.usedperson = " ";
                ipmodel.organization = " ";
                ipmodel.department = " ";
                ipmodel.usedinternet = 1;
                ipmodel.description = " ";
                ipmodel.macaddress = " ";
                ipmodel.modifydate = DateTime.Now;
                ipmodel.productdate = DateTime.MinValue;
                ipbll.Update(ipmodel);
            }
            Maticsoft.Common.MessageBox.Show(this, "更新成功,请刷新页面!");
        }
    }
}